#include<iostream>
#include<string>
using namespace std;
string s;
int main()
{
	int t;
	cin >> t;
	while (t--) {
		cin >> s;
		string temp = s;
		int cnt = 0;
		for (int i = 0; i < s.size() / 2; i++) {
			temp[i] = s[i];
			temp[s.size() - 1 - i] = s[i];
		}
		for (int i = 0; i < s.size(); i++) {
			if (s[i] == '9')cnt++;
		}
		if (cnt == s.size()) {
			cout << 1;
			for (int i = 0; i < cnt - 1; i++) {
				cout << 0;
			}
			cout << 1 << endl;
			continue;
		}
		cout << "s==" << s << endl;
		cout << "temp=" << temp << endl;
		if (s.size() & 1) {
			if (s[s.size() / 2 + 1] < temp[temp.size() / 2 + 1]) {
				cout << temp << endl;
			}
			else {
			/*	swap(temp[temp.size() / 2 - 1], temp[temp.size() / 2]);
				temp[temp.size() / 2 + 1] = temp[temp.size() / 2];*/
				temp[temp.size() / 2] = s[s.size() / 2 + 1];
				cout << temp << endl;
			}
		}
		else {
			if (s[s.size() / 2] < temp[temp.size() / 2]) {
				cout << temp << endl;
			}
			else {
				//cout << "1111" << endl;
				/*s[s.size() / 2 - 1] = s[s.size() / 2];
				temp = s;
				for (int i = 0; i < s.size() / 2; i++) {
					temp[temp.size() - 1 - i] = temp[i];
				}*/
				temp[temp.size() / 2 - 1] = temp[temp.size() / 2] = s[temp.size() / 2];
				cout << temp << endl;
			}
		}
	}
	return 0;
}